<!-- Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->

<link rel="import" href="../common/cr-cursor-manager.html">
<link rel="import" href="../common/cr-keyboard.html">
<link rel="import" href="cr-issue-inbox-section.html">

<polymer-element name="cr-issue-inbox" attributes="issues weeks showRecentActivity"
                 on-expanded="{{ handleSectionToggled }}"
                 on-collapsed="{{ handleSectionToggled }}">
    <template>
        <link rel="stylesheet" href="../common/common.css">

        <template if="{{ issues.draft.length }}">
            <h1>Issues with Drafts</h1>
            <cr-issue-inbox-section issues="{{ issues.draft }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <template if="{{ issues.outgoing.length }}">
            <h1>Outgoing</h1>
            <cr-issue-inbox-section issues="{{ issues.outgoing }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <template if="{{ issues.unsent.length }}">
            <h1>Unsent</h1>
            <cr-issue-inbox-section issues="{{ issues.unsent }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <template if="{{ issues.incoming.length }}">
            <h1>Incoming</h1>
            <cr-issue-inbox-section issues="{{ issues.incoming }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <template if="{{ issues.cc.length }}">
            <h1>CCed</h1>
            <cr-issue-inbox-section issues="{{ issues.cc }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <template if="{{ issues.closed.length }}">
            <h1>Recently Closed</h1>
            <cr-issue-inbox-section issues="{{ issues.closed }}" weeks="{{ weeks }}" showRecentActivity="{{ showRecentActivity }}"></cr-issue-inbox-section>
        </template>

        <cr-cursor-manager id="cursorManager"
                           stopSelector="cr-issue-inbox-section /deep/ .issue"
                           ></cr-cursor-manager>
        <cr-keyboard on-key-j="{{ handleNextIssueKey }}"
                     on-key-k="{{ handlePreviousIssueKey }}"
                     on-key-enter="{{ handleOpenTargetIssueKey }}"
                     on-key-o="{{ handleOpenTargetIssueKey }}"
                     global></cr-keyboard>
    </template>
    <script>
        Polymer({
            issuesChanged: function() {
                this.$.cursorManager.resetStops();
            },
            weeksChanged: function() {
                this.$.cursorManager.resetStops();
            },
            showRecentActivityChanged: function() {
                this.$.cursorManager.resetStops();
            },
            handleSectionToggled: function(event) {
                this.$.cursorManager.resetStops();
            },
            handleNextIssueKey: function(event) {
                this.$.cursorManager.next(event);
            },
            handlePreviousIssueKey: function(event) {
                this.$.cursorManager.previous(event);
            },
            handleOpenTargetIssueKey: function(event) {
                this.$.cursorManager.open(event);
            },
        });
    </script>
</polymer-element>
